package com.run.service.impl;



import com.github.pagehelper.PageHelper;
import com.run.mapper.EbProductCategoryMapper;
import com.run.mapper.EbProductMapper;
import com.run.model.EbProductCategory;
import com.run.service.ProductClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ProductClassServiceImpl implements ProductClassService {
   @Autowired
   private EbProductMapper ebProductMapper;

    @Autowired
    private EbProductCategoryMapper ebProductCategoryMapper;

    //提供查询大小类的Map方法
    @Override
    public Map<String, List<EbProductCategory>> findBigAndSmallCategory() {
        //1.查询所有大类
        List<EbProductCategory> Bigs = ebProductCategoryMapper.selectBigCategory();
        //2.查询所有小类
        List<EbProductCategory> Smalls = ebProductCategoryMapper.selectSmallCategory();
        //3.将结果封装到map集合
        Map<String,List<EbProductCategory>> categoryMap=new HashMap<>();
        categoryMap.put("Bigs",Bigs);
        categoryMap.put("Smalls",Smalls);

        return categoryMap;
    }

    @Override
    public Integer save(EbProductCategory ebProductCategory) {

        ebProductCategoryMapper.insertSelective(ebProductCategory);
        ebProductCategory.setEpcParentId(ebProductCategory.getEpcId());
       //  ebProductCategoryMapper.updateByPrimaryKey(ebProductCategory);
       // System.out.println(ebProductCategoryMapper.updateByPrimaryKey(ebProductCategory));


        return ebProductCategoryMapper.updateByPrimaryKey(ebProductCategory);
    }

    @Override
    public EbProductCategory selectOne(Integer epcId) {
        return ebProductCategoryMapper.selectByPrimaryKey(epcId);
    }

    @Override
    public Integer updateEbProductCategory(EbProductCategory ebProductCategory) {
        return ebProductCategoryMapper.updateByPrimaryKey(ebProductCategory);
    }

    @Override
    public Integer delete(Integer epcId) {
        return ebProductCategoryMapper.deleteByPrimaryKey(epcId);
    }

}

